package com.ruoyi.jpjstb.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.jpjstb.service.ProjectService;
import com.ruoyi.jpjstb.service.param.ParamService;
import com.ruoyi.jpjstb.service.person.PersonService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author zeo
 * @explain 项目管理模块控制层
 * @date 2020/4/1 11:10
 */
@Controller
@RequestMapping("/projectManage")
public class ProjectManageController extends BaseController {

    private String prefix = "jpjstb/projectmanage";

    @Autowired
    private ProjectService projectService;
    @Autowired
    private ParamService paramService;
    @Autowired
    private PersonService personService;

    /**
     * 跳转分页页面
     */
    @RequiresPermissions("project:user:view")
    @GetMapping()
    public String projectManage(ModelMap mmp) {
        mmp.put("proType", paramService.findParam("项目类型"));
        mmp.put("proStatus", paramService.findParam("项目状态"));
        mmp.put("belongComp", paramService.findParam("区域公司"));
        mmp.put("person", personService.findPerson());
        return prefix + "/ProjectManage";
    }

    @RequiresPermissions("project:user:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo findProject(@RequestParam Map<String, Object> map) {
        startPage();
        List<Map<String, Object>> list = projectService.findProjectList(map);
        return getDataTable(list);
    }

    @RequiresPermissions("project:user:save")
    @GetMapping("/add")
    public String addProject(ModelMap mmp) {
        mmp.put("proType", paramService.findParam("项目类型"));
        mmp.put("proStatus", paramService.findParam("项目状态"));
        mmp.put("belongComp", paramService.findParam("区域公司"));
        mmp.put("person", personService.findPerson());
        return prefix + "/AddProjectManage";
    }

    @RequiresPermissions("project:user:save")
    @PostMapping("/save")
    @ResponseBody
    public AjaxResult addProject(@RequestParam Map map) {
        return toAjax(projectService.savePorject(map));
    }

    @RequiresPermissions("project:user:remove")
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult removeProject(String ids) {
        return toAjax(projectService.removePorject(ids));
    }

    @RequiresPermissions("project:user:save")
    @GetMapping("/edit/{id}")
    public String editProject(@PathVariable("id") String id, ModelMap mmp) {
        mmp.put("proType", paramService.findParam("项目类型"));
        mmp.put("proStatus", paramService.findParam("项目状态"));
        mmp.put("belongComp", paramService.findParam("区域公司"));
        mmp.put("person", personService.findPerson());
        mmp.put("project", projectService.findProject(id));
        return prefix + "/editProjectManage";
    }

    @RequiresPermissions("project:user:view")
    @PostMapping("/view")
    @ResponseBody
    public List<Map<String, Object>> getView() {
        return projectService.getProView();
    }

    @RequiresPermissions("project:user:view")
    @PostMapping("/getCount")
    @ResponseBody
    public Map<String, Object> getCount(String belongComp) {
        return projectService.getCount(belongComp);
    }

    @RequiresPermissions("project:user:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(@RequestParam Map<String, Object> map) {
        return projectService.export(map);
    }
}
